import dayjs from "dayjs";

// 距离现在过去的时间
export const awaitTime = (time: string) => {
  const date1 = dayjs()
  const date2 = dayjs(time)
  const _hour = date1.diff(date2, 'hour') // 差异-小时
  const _minute = date1.diff(date2, 'minute') // 差异-分钟
  return {
    minute: _minute,
    desc: `${_hour}小时${_minute%60}分钟`
  }
}

// 拨打电话 mobile === service 则是拨打客服
export function callPhone (mobile: string) {
  if(mobile){
    let phoneNumber = mobile === 'service' ? '15012752193' : mobile;
    
    uni.makePhoneCall({phoneNumber}); 
  }
}

export function maskPhone(phone: string) {
  if (!phone || phone.length !== 11) {
      return phone
  }
  return `${phone.substring(0, 3)}****${phone.substring(7)}`;
}